﻿using System;
using System.Drawing;
using ZYCommon;

namespace TextEditor
{
   

    public class ZYTextHRule : ZYTextElement
    {                

        public ZYTextHRule()
        {
            this.LineHeight = 1;//默认水平线宽度
        }

        public override string GetXMLName()
        {
            return "hr";
        }

        public override bool isField()
        {
            return false;
        }

        public override bool isNewLine()
        {
            return true;
        }

        public override bool isTextElement()
        {
            return false;
        }

        public override bool OwnerWholeLine()
        {
            return true;
        }

        public override bool RefreshSize()
        {
            this.Width = base.myParent.GetClientWidth();
            this.Height = base.myOwnerDocument.View.DefaultRowHeight();
            return true;
        }

        public override bool RefreshView()
        {
            int lineHeight = this.LineHeight;
            if (lineHeight <= 0)
            {
                lineHeight = 1;
            }          
            Pen myPen = base.myOwnerDocument.View._CreatePen(this.ForeColor, lineHeight);
            if (this.DashStyle == 1)
            {
                myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
            }
            else
            {
                myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
            }
            int y = (this.myBounds.Top + ((this.myBounds.Height - lineHeight) / 2)) + 1;
            base.myOwnerDocument.View.DrawLine(myPen, this.myBounds.Left, y, this.myBounds.Right, y);
            return true;
        }

        public override string ToZYString()
        {
            return "";
        }               

        /***
         * 水平线颜色
         */
        public override Color ForeColor
        {
            get
            {
                return base.myAttributes.GetColor("forecolor");
            }
            set
            {
                base.myAttributes.SetValue("forecolor", value);
            }
        }

        public int DashStyle
        {
            get
            {
                return base.myAttributes.GetInt32("dashstyle");
            }
            set
            {
                base.myAttributes.SetValue("dashstyle", value);
            }
        }

        /***
         * 宽度
         */
        public int LineHeight
        {
            get
            {
                return base.myAttributes.GetInt32("height");
            }
            set
            {
                if ((value >= 1) && (value <= 10))
                {
                    base.myAttributes.SetValue("height", value);
                }
            }
        }
    }
}

